package com.example.opslog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Author: Administrator
 * @Description:
 * @Date: Created in 2019-06-04 10:10
 * @Modified By:
 */
@Configuration
@EnableAsync
public class ExecutorConfig {

  @Bean(name = "customizeExecutor")
  public TaskExecutor executor() {

    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

    taskExecutor.setCorePoolSize(10);
    taskExecutor.setMaxPoolSize(50);
    taskExecutor.setQueueCapacity(100);

    taskExecutor.setThreadNamePrefix("customize-executor-");
    taskExecutor.setKeepAliveSeconds(10);
    taskExecutor.setAllowCoreThreadTimeOut(false);
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);

    return taskExecutor;
  }
}
